{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>发布系统消息</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="notice_title" lay-verify="required" placeholder="标题" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">发布者：</label>
                            <div class="layui-input-block">
                                <input type="text" name="notice_publish_user" lay-verify="required" placeholder="发布者" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group" id="notice_range">
                            <label class="layui-form-label">发布范围：</label>
                            <div class="layui-input-block">
                                <select name="notice_range"  lay-filter="role1">
                                    <option value="1" selected>全部用户</option>
                                    <option value="2" >部分用户</option>
                                    <option value="3" >福利权限</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 hidden" id="user_id">
                            <label class="layui-form-label">用户：</label>
                            <div class="layui-input-block">
                                <select name="notice_user"  xm-select="select" xm-select-search="" xm-select-search-type="dl">
                                    {foreach name="user" item="vo"}
                                    <option value="{$vo.user_id}" >{$vo.user_username}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 hidden" id="th_id">
                            <label class="layui-form-label">福利：</label>
                            <div class="layui-input-block">
                                <select name="notice_th"  xm-select="select1" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    {foreach name="thRule" item="vo1"}
                                    <option value="{$vo1.rule_id}" >{$vo1.rule_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">消息内容：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor"></div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">发布
                                </button>
<!--                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            data.field.notice_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('noticeAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });

        form.on('select(role1)', function(data){
            notice_range = data.value;
            if(data.value == 1){
                $("#user_id").addClass('hidden');
                $("#th_id").addClass('hidden');
            }else if(data.value == 2){
                $("#user_id").removeClass('hidden');
                $("#th_id").addClass('hidden');
            }else {
                $("#user_id").addClass('hidden');
                $("#th_id").removeClass('hidden');
            }
        });
    });
</script>

</body>
</html>
